class PluginManager {
  constructor() {
    this.plugins = new Map();
  }

  async loadPlugin(pluginPath) {
    try {
      const plugin = await import(pluginPath);
      this.plugins.set(pluginPath, plugin);
      if (plugin.activate) {
        await plugin.activate(this);
      }
      return plugin;
    } catch (error) {
      console.error(`Failed to load plugin from ${pluginPath}:`, error);
      throw error;
    }
  }

  unloadPlugin(pluginPath) {
    const plugin = this.plugins.get(pluginPath);
    if (plugin && plugin.deactivate) {
      plugin.deactivate();
    }
    this.plugins.delete(pluginPath);
  }

  getPlugin(pluginPath) {
    return this.plugins.get(pluginPath);
  }

  getAllPlugins() {
    return Array.from(this.plugins.values());
  }
}

module.exports = PluginManager;